fix: no-op clients without api key#544
Merged
marandaneto merged 1 commit intoPostHog:mainfrom Apr 30, 2026
Merged
Conversation
6 tasks
f47fb24 to
e955b1c
Compare
e955b1c to
aa8c91f
Compare
Contributor
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
posthog/test/test_client.py:77-86
**Non-parameterised test duplicates existing parameterised case**
The `""` input here exercises the same code path and assertions (`api_key == ""`, `disabled == True`, same error-log message) already covered by the `whitespace_only` row in `test_trims_api_key_whitespace`. Per the team's preference for parameterised tests and the OnceAndOnlyOnce rule, adding a third row `("empty_string", "", "", True, True)` would be cleaner. The `capture()` no-op assertion is the only genuinely new thing here, and that could live in a focused test (or the parameterised test itself could grow the assertion).
```python
("empty_string", "", "", True, True),
```
Reviews (1): Last reviewed commit: "fix: allow disabled clients without api ..." | Re-trigger Greptile |
ioannisj
approved these changes
Apr 30, 2026
ioannisj
left a comment
There was a problem hiding this comment.
LG, left a minor comment on disabled checks.
989087d to
e19f82d
Compare
e19f82d to
53cddbb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Fixes #173.
When a direct client is created with a project API key that is missing or trims to an empty string, the SDK now logs the empty-key warning and marks that client as disabled so calls are no-ops. Feature flag loading and direct flag decision APIs also return early for disabled clients to avoid malformed requests with an empty token.
Module-level setup now preserves the client’s auto-disabled state after trimming a whitespace-only key.
💚 How did you test it?
uv run pytest posthog/test/test_client.py posthog/test/test_module.py -quv run ruff format --check posthog/__init__.py posthog/client.py posthog/test/test_client.py posthog/test/test_module.pyuv run ruff check posthog/__init__.py posthog/client.py posthog/test/test_client.py posthog/test/test_module.py📝 Checklist
If releasing new changes
sampo addto generate a changeset filereleaselabel to the PR